package com.hhkj.admin.student.controller;

import cn.hutool.json.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.hhkj.admin.student.domain.StudentCourseTrainCount;
import com.hhkj.admin.student.model.req.StudentLoginLogReq;
import com.hhkj.admin.student.service.base.TrainCountService;
import com.hhkj.admin.student.service.biz.TrainCountBizService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.excl.utils.ExcelUtils;
import com.ruoyi.system.domain.StudentLoginLog;
import org.apache.ibatis.javassist.ClassPool;
import org.apache.ibatis.javassist.CtClass;
import org.apache.ibatis.javassist.CtField;
import org.apache.ibatis.javassist.NotFoundException;
import org.apache.ibatis.javassist.bytecode.AnnotationsAttribute;
import org.apache.ibatis.javassist.bytecode.ConstPool;
import org.apache.ibatis.javassist.bytecode.FieldInfo;
import org.apache.ibatis.javassist.bytecode.annotation.Annotation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 练习统计Controller
 *
 * @author ruoyi
 * @since 2023-05-23
 */
@RestController
@RequestMapping("/train/count")
public class TrainCountController extends BaseController {
    @Autowired
    private TrainCountBizService trainCountBizService;

    /**
     * 分页查询登录日志
     *
     * @return 登录日志
     */
    @PreAuthorize("@ss.hasPermi('train:count:pagelogin')")
    @PostMapping("/page/login")
    public TableDataInfo pageLoginLog(@RequestBody StudentLoginLogReq studentLoginLogReq) {
        startPageBody(studentLoginLogReq);
        return getDataTable(trainCountBizService.pageLoginLog(studentLoginLogReq));
    }

    /**
     * 分页查询练习统计情况
     *
     * @return 练习统计情况
     */
    @PreAuthorize("@ss.hasPermi('train:count:page')")
    @PostMapping("/page")
    public TableDataInfo page(@RequestBody StudentCourseTrainCount trainCount) {
        startPageBody(trainCount);
        return trainCountBizService.pagePracticeCount(trainCount);
    }

    /**
     * 导出练习统计情况
     *
     * @return 练习统计情况
     */
    @Log(title = "导出练习统计情况", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('train:count:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody StudentCourseTrainCount trainCount) {
        Workbook workbook = trainCountBizService.exportPracticeCount(trainCount);
        ExcelUtils.downLoadExcel("练习统计情况", response, workbook);
    }
}
